package com.sky.controller.user;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 分类管理
 */
@RestController("userCategoryController")
@RequestMapping("/user/category")
@Api(tags = "分类相关接口")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //--6--根据类型查询分类
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result selectByType(Integer type) {
        log.info("根据类型查询分类，参数为：{}", type);
        List<Category> categoryList=categoryService.selectByType(type);

        //类型: 1菜品分类 2套餐分类
        categoryList=categoryList.stream().map(item->{
            if (item.getType()==2){
                item.setName("["+item.getName()+"]");
            }
            return item;
        }).collect(Collectors.toList());
        return Result.success(categoryList);
    }
}
